package com.example.springboot.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.controller.dto.ArticleDTO;
import com.example.springboot.controller.dto.FollowDTO;
import com.example.springboot.entity.Articles;
import com.example.springboot.entity.Follows;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 用户关注表 Mapper 接口
 * </p>
 *
 * @author
 * @since
 */
public interface FollowsMapper extends BaseMapper<Follows> {

    @Select("SELECT COUNT(1) FROM follows WHERE follower_id = #{followerId} AND following_id = #{followingId}")
    Integer selectisFollow(Integer followerId, Integer followingId);

    @Delete("DELETE FROM follows WHERE follower_id = #{followerId} AND following_id = #{followingId}")
    void deleteisFollowById(Integer followerId, Integer followingId);


    @Select("SELECT a.*, u.nickName AS nickName, u.avatar_url AS avatar " +
            "FROM follows a LEFT JOIN sys_user u ON a.following_id = u.id " +
            "${ew.customSqlSegment}") // 支持 MyBatis-Plus 条件构造器
    Page<FollowDTO> selectArticlePageWithAuthor(Page<FollowDTO> page, @Param(Constants.WRAPPER) Wrapper<Follows> wrapper);

}
